﻿using System;

//自定义
using DreamCube.Foundation.Basic.Utility;
using DreamCube.Foundation.Basic.Objects;

namespace DreamCube.Foundation.WMI
{
    /// <summary>
    /// 磁盘分区实体类
    /// </summary>
    public class HardDiskPartitionModel
    {
        /// <summary>
        /// 块大小
        /// </summary>
        [ManagementObjectPropertyMapping("BlockSize")]
        public UInt64 BlockSize
        {
            get;
            set;
        }

        /// <summary>
        /// 是否包含引导表
        /// </summary>
        [ManagementObjectPropertyMapping("Bootable")]
        public Boolean Bootable
        {
            get;
            set;
        }

        /// <summary>
        /// 是否主分区
        /// </summary>
        [ManagementObjectPropertyMapping("PrimaryPartition")]
        public Boolean PrimaryPartition
        {
            get;
            set;
        }

        /// <summary>
        /// 开始偏移量
        /// </summary>
        [ManagementObjectPropertyMapping("StartingOffset")]
        public UInt64 StartingOffset
        {
            get;
            set;
        }

        /// <summary>
        /// 块数
        /// </summary>
        [ManagementObjectPropertyMapping("NumberOfBlocks")]
        public UInt64 NumberOfBlocks
        {
            get;
            set;
        }

        /// <summary>
        /// 序号
        /// </summary>
        [ManagementObjectPropertyMapping("Index")]
        public UInt32 Index
        {
            get;
            set;
        }

        /// <summary>
        /// 设备ID
        /// </summary>
        [ManagementObjectPropertyMapping("DeviceID")]
        public String DeviceID
        {
            get;
            set;
        }

        /// <summary>
        /// 分区标题
        /// </summary>
        [ManagementObjectPropertyMapping("Caption")]
        public String Caption
        {
            get;
            set;
        }

        /// <summary>
        /// 是否引导分区
        /// </summary>
        [ManagementObjectPropertyMapping("BootPartition")]
        public Boolean BootPartition
        {
            get;
            set;
        }

        /// <summary>
        /// 盘符名
        /// </summary>
        [ManagementObjectPropertyMapping("Name")]
        public String Name
        {
            get;
            set;
        }

        /// <summary>
        /// 大小容量
        /// </summary>
        [ManagementObjectPropertyMapping("Size", typeof(FileSystemSizeDataConvert))]
        public FileSystemSize Size
        {
            get;
            set;
        }

        /// <summary>
        /// 剩余空间
        /// </summary>
        [ManagementObjectPropertyMapping("FreeSpace", typeof(FileSystemSizeDataConvert))]
        public FileSystemSize FreeSpace
        {
            get;
            set;
        }

        public HardDiskPartitionModel()
        {
            this.FreeSpace = new FileSystemSize(0);
        }

        /// <summary>
        /// 使用率
        /// </summary>
        /// <param name="roundSize">保留多少位小数，默认为两位</param>
        /// <returns></returns>
        public Double GetUseRate(Int32 roundSize = 2)
        {
            return Math.Round(Convert.ToDouble(FreeSpace.B / Size.B * 100), roundSize);
        }
    }
}
